package org.jluzh.registUsingHibernate.service;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.jluzh.registUsingHibernate.domain.User;

public class UserService
{
    public void CreateUser(User user)
    {
	Configuration conf = new Configuration().configure();
	//以Configuration创建SessionFactory
	SessionFactory sf = conf.buildSessionFactory();
	//创建Session
	Session sess = sf.openSession();
	//
	Transaction tx = sess.beginTransaction();
	user.setId(3);
	sess.save(user);
	tx.commit();
	sess.close();
	sf.close();
    }
}
